package com.bigmodel.baidu;

import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.*;
import java.time.temporal.*;
import java.util.Date;

import static java.time.temporal.ChronoUnit.HOURS;

public class GPTDateTime {

    public static void main(String[] args) {
        String[] startEndTime = getStartEndTime3();
        System.out.println("Start Time: " + startEndTime[0]);
        System.out.println("End Time: " + startEndTime[1]);
    }

    public static String[] getStartEndTime() {
        //获取当前时间
        LocalDateTime now = LocalDateTime.now();
        //当前时间减去1小时
        LocalDateTime startDateTime = now.minusHours(1);
        //开始时间增加1小时
        LocalDateTime endDateTime = startDateTime.plusHours(1);
        //格式化
        String startTime = startDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        //格式化
        String endTime = endDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return new String[]{startTime, endTime};
    }

    public static String[] getStartEndTime2() {
        //获取当前时间
        LocalDateTime now = LocalDateTime.now();
        //当前时间减去1分钟
        LocalDateTime startDateTime = now.minusMinutes(1);
        //开始时间增加1分钟
        LocalDateTime endDateTime = now.plusMinutes(1);
        //当前时间减去1小时
        //LocalDateTime startDateTime = now.minusHours(1);
        //开始时间增加1小时
        //LocalDateTime endDateTime = now.plusHours(1);
        //当前时间减去1天
        //LocalDateTime startDateTime = now.minusDays(1);
        //开始时间增加1天
        //LocalDateTime endDateTime = now.plusDays(1);


        //格式化
        String startTime = startDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        //格式化
        String endTime = endDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return new String[]{startTime, endTime};
    }


    public static String[] getStartEndTime3() {
        //获取当前时间
        LocalDateTime now = LocalDateTime.now();
        //步骤一:开始时间计算
        LocalDateTime startTime = now.toLocalDate().atTime(7, 30);
        //步骤二:结束时间计算
        LocalDateTime endTime = now.toLocalDate().atTime(9, 0);
        //步骤三:格式化开始时间,结束时间
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String startTimeStr = formatter.format(startTime);
        String endTimeStr = formatter.format(endTime);
        //步骤四:返回数组
        return new String[]{startTimeStr, endTimeStr};
    }
}
